package com.studyspringcloud.order.control;

import com.studyspringcloud.order.VO.ResultVO;
import com.studyspringcloud.order.dto.OrderDTO;
import com.studyspringcloud.order.remote.ProductRemote;
import com.studyspringcloud.order.service.OrderService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    ProductRemote productRemote;

    @Autowired
    OrderService orderService;


    /**
     * 1参数校验
     * 2查询商品信息(调用商品服务)
     * 3计算总价
     * 4扣库存
     * 5订单入库
     */
    @RequestMapping("/createOrder")
    public ResultVO create(OrderDTO dto){
        if(StringUtils.isBlank(dto.getBuyerName()) ||
                StringUtils.isBlank(dto.getBuyerPhone()) ||
                StringUtils.isBlank(dto.getBuyerAddress()) ||
                dto.getOrderDetailList().size() <=0 ||
                StringUtils.isBlank(dto.getBuyerOpenid()) ){
            return ResultVO.error("参数错误");
        }
        ResultVO vo = productRemote.getProductInfoById(1);
        orderService.create(dto);
        System.out.println(vo.getData());
        return productRemote.findCategoryById(1);
    }
}
